package main

/**
 GO 协程 轻量级线程
 */
import (
	"fmt"
	"time"
)

func f(from string) {
	for i := 0; i < 3; i++ {
		fmt.Println(from, ":", i)
	}
}

func newTask() {
	i := 0
	for {
		i++
		fmt.Printf("new goroutine: i = %d\n", i)
		time.Sleep(1 * time.Second) //延时1s
	}
}

func main() {
	f("direct")

	go f("goroutine")

	go func(msg string) {
		fmt.Println(msg)
	}("going")

	//接受键盘输入回车后退出
	var input string
	fmt.Scanln(&input)
	fmt.Println("done")

	//创建一个 goroutine，启动另外一个任务
	//go newTask()

	//i := 0
	//main goroutine 循环打印
	/*
	for {
		i++
		fmt.Printf("main goroutine: i = %d\n", i)
		time.Sleep(1 * time.Second) //延时1s
	}
	*/

}